<!-- subpkg_consult/department/department -->
<script lang="ts" setup>
  import { departmentListApi } from '@/pages/api/consult'
  import type { DepartData } from '@/types/consult'
  import { onLoad } from '@dcloudio/uni-app'
  import { computed, ref } from 'vue'
  const depList = ref<DepartData[]>([])
  onLoad(async () => {
    const res = await departmentListApi()
    depList.value = res
  })

  const activeIndex = ref(0)

  const childList = computed(() => {
    return depList.value[activeIndex.value]?.child
  })

  defineProps<{
    type: string
    illnessType: string
  }>()
</script>

<template>
  <view class="department-page">
    <scroll-view scroll-y class="department-primary">
      <view
        v-for="(item, index) in depList"
        :key="item.id"
        class="department-item"
        :class="{ active: activeIndex === index }"
        @click="activeIndex = index"
      >
        {{ item.name }}
      </view>
    </scroll-view>
    <scroll-view class="department-secondary">
      <navigator
        v-for="item in childList"
        hover-class="none"
        :url="`/subpkg_consult/description/description?type=${type}&illnessType=${illnessType}&depId=${item.id}`"
        class="department-item"
      >
        {{ item.name }}
      </navigator>
    </scroll-view>
  </view>
</template>

<style lang="scss">
  @import './department.scss';
</style>
